//
//  SDHSportsInteCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/6.
//

#import "SDHSportsInteCell.h"
#import "SDHSportsInteListModel.h"
#import "UIImageView+YQAdd.h"

@interface SDHSportsInteCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *leftAvatarImg;
@property (nonatomic, strong) UILabel *leftNameLb;
@property (nonatomic, strong) UIImageView *vsImg;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UIImageView *rightAvatarImg;
@property (nonatomic, strong) UILabel *rightNameLb;

@end

@implementation SDHSportsInteCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    self.backgroundColor = [UIColor clearColor];
    
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor whiteColor];
    view.clipsToBounds = YES;
    view.layer.cornerRadius = 15;
    [self.contentView addSubview:view];
    self.bgView = view;
    
    UIImageView *imgView = [UIImageView new];
    imgView.image = [UIImage imageNamed:@"touxiang"];
    [self.contentView addSubview:imgView];
    self.leftAvatarImg = imgView;
    
    UILabel *label = [UILabel new];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:15];
    label.numberOfLines = 0;
//    label.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:label];
    self.leftNameLb = label;
    
    imgView = [UIImageView new];
    imgView.image = [UIImage imageNamed:@"vs"];
    [self.contentView addSubview:imgView];
    self.vsImg = imgView;
    
    label = [UILabel new];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:16];
    label.backgroundColor = [UIColor grayColor];
    label.textColor = [UIColor whiteColor];
    label.layer.masksToBounds = YES;
    label.layer.cornerRadius = 8;
    [self.contentView addSubview:label];
    self.timeLb = label;
    
    imgView = [UIImageView new];
    imgView.image = [UIImage imageNamed:@"touxiang"];
    [self.contentView addSubview:imgView];
    self.rightAvatarImg = imgView;
    
    label = [UILabel new];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:15];
    label.numberOfLines = 0;
//    label.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:label];
    self.rightNameLb = label;
    
    __weak typeof(self) weakSelf = self;
    UIView *superview = weakSelf.contentView;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(superview).insets(UIEdgeInsetsMake(0, 10, 20, 10));
    }];
    
    [self.leftAvatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(superview).offset(40);
        make.top.equalTo(superview).offset(10);
        make.width.equalTo(@50);
        make.height.equalTo(@50);
    }];
    
    [self.leftNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.leftAvatarImg).offset(-10);
        make.right.equalTo(weakSelf.leftAvatarImg).offset(10);
        make.top.equalTo(weakSelf.leftAvatarImg.mas_bottom).offset(10);
    }];
    
    [self.vsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(superview);
        make.top.equalTo(superview).offset(15);
    }];
    
    [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(superview);
        make.top.equalTo(weakSelf.vsImg.mas_bottom).offset(15);
    }];
    
    [self.rightAvatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(superview).offset(-40);
        make.top.equalTo(superview).offset(10);
        make.width.equalTo(@50);
        make.height.equalTo(@50);
    }];
    
    [self.rightNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.rightAvatarImg).offset(-10);
        make.right.equalTo(weakSelf.rightAvatarImg).offset(10);
        make.top.equalTo(weakSelf.rightAvatarImg.mas_bottom).offset(10);
    }];
    
    // 赋值，调试用
//    self.leftNameLb.text = @"Brisbane Roar Girl";
//    self.timeLb.text = @" 03-05 12:10  ";
//    self.rightNameLb.text = @"Canberra United W";
}

- (void)updateContent:(id)obj {
    if (![obj isKindOfClass:[SDHSportsInteListModel class]]) {
        return;
    }
    
    SDHSportsInteListModel *model = (SDHSportsInteListModel *)obj;
    self.leftNameLb.text = model.guest_en_name;
    self.rightNameLb.text = model.host_en_name;
    self.timeLb.text = [NSString stringWithFormat:@" %@ ", model.time];
    
    [self.leftAvatarImg setImageWithURL:[NSURL URLWithString:model.guest_logo] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    [self.rightAvatarImg setImageWithURL:[NSURL URLWithString:model.host_logo] placeholderImage:[UIImage imageNamed:@"touxiang"]];
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
